<template>
  <div class="systemgroup-page page-main">
    <search-form :model="searchParams" @search="search">
      <a-form-item label="数据搜索" name="prop">
        <a-input v-model:value="searchParams.keywords" placeholder="请输入" />
      </a-form-item>
    </search-form>
    <div class="table-toolbar">
      <add-button @click="add()" />
    </div>
    <g-table ref="tableRef" :columns="columns" :api="getPageList" :params="searchParams" />

    <systemgroupDetail v-model:visible="visible" :data="activeRow" @change="search(false)" />
  </div>
</template>

<script setup lang="tsx">
import { systemgroupDel, getPageList } from './api';
import type { Isystemgroup } from './entity';
import systemgroupDetail from './detail.vue';
import groupData from '../groupData/index.vue';
const searchParams = reactive({
  keywords: ''
})
const router = useRouter();
let visible = $ref(false)
let open = $ref(false)
const { tableRef, columns, search } = useTable<Isystemgroup>([
  { title: '数据组名称', dataIndex: 'name' },
  { title: '简介', dataIndex: 'info' },
  {
    title: '操作',
    dataIndex: 'op',
    customRender: ({ record }) => (
      <>
        <table-button onClick={() => getList(record)}>数据列表</table-button>
        <table-button onClick={() => add(record)}>编辑</table-button>
        <confirm-button danger onClick={() => remove(record)}>删除</confirm-button>
      </>
    )
  }
])

let activeRow = $ref<Partial<Isystemgroup>>({})
function add(row: Partial<Isystemgroup> = {}) {
  activeRow = { ...row }
  visible = true
}
function getList(row: Partial<Isystemgroup> = {}) {
  router.push({ name: "groupData", query: { id: row.id, formId: row.formId } });
}
function remove({ id }: Isystemgroup) {
  systemgroupDel(id as number).then(() => {
    AntMessage.success('已删除')
    search(false)
  })
}
</script>

<style lang="scss"></style>